package com.todomvc.tests;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.todomvc.fw.NavigationHelper;
import com.todomvc.fw.Todo;
import com.todomvc.fw.TodoHelper;
import com.todomvc.fw.Todos;

public class TodoToggleTests extends TestBase {

	private NavigationHelper navMan;
	private TodoHelper todoMan;

	
	@BeforeClass
	public void getManagers () {
		todoMan = manager.getTodoHelper();
		navMan = manager.getNavigationHelper();
		navMan.openAngularPage();
	}
	
	
	@Test
	public void lastTodoShouldBeToggled () {

		// Adding an item to ensure that we have something to be toggled to 'complete'
		todoMan.add(new Todo("Say something easy"));

		Todos oldList = todoMan.getTodos();

		todoMan.toggleLast();

		Todos newList = todoMan.getTodos();
		assertThat(newList, equalTo(oldList.withLastToggled()));
	}

	@Test
	public void firstTodoShouldBeToggled () {

		// Adding an item to ensure that we have something to be toggled to 'complete'
		todoMan.add(new Todo("Say something easy"));
		todoMan.add(new Todo("Say something tough"));

		Todos oldList = todoMan.getTodos();

		todoMan.toggleFirst();

		Todos newList = todoMan.getTodos();
		assertThat(newList, equalTo(oldList.withFirstToggled()));
	}

	@Test
	public void anyTodoShouldBeToggled () {

		// Adding an item to ensure that we have something to be toggled to 'complete'
		todoMan.add(new Todo("Say something tough"));
		todoMan.add(new Todo("Say something easy"));
		todoMan.add(new Todo("Say something tough"));

		Todos oldList = todoMan.getTodos();

		int index = 2;
		todoMan.toggleNth(index);

		Todos newList = todoMan.getTodos();
		assertThat(newList, equalTo(oldList.withNtsToggled(index)));
	}

	
}
